import React from 'react'

import './style.scss'

class SearchInput extends React.Component{
    constructor(props, context){
        super(props, context)
        this.state = {
            value: ''
        }
    }
    render() {
        return (
            <div className="middle">
                <i className="iconfont icon-shoucang"></i>
                <input type="text"
                className="search-input"
                value={this.state.value}
                onChange={this.changeHandle.bind(this)}
                onKeyUp={this.keyUpHandle.bind(this)}
                placeholder="请输入关键字"/>
            </div>
        )
    }
    componentDidMount() {
        this.setState({
            value: this.props.value || ''
        })
    }
    changeHandle(e) {
        this.setState({
            value: e.target.value
        })
    }
    keyUpHandle(e) {
        if(e.keyCode != 13){
            return
        }
        this.props.enterHandle(this.state.value)
    }
}

export default SearchInput